package yimport

import (
	"yunj/app/controller/admin/demo"
	"yunj/pkg/yunj/core/builder"
	"yunj/pkg/yunj/core/builder/yimport"

	"github.com/gin-gonic/gin"
)

type Index struct {
	demo.Controller
}

// 示例
func (ctrl *Index) Index(ctx *gin.Context) {
	importBuilder := builder.NewImport(ctx, "demo").
		Sheet([]string{"Sheet1", "Sheet2"}).
		Cols(func(i *builder.Import, sheet string) (cols []yimport.Col, err error) {
			cols = []yimport.Col{
				{
					Field:   "name",
					Title:   "姓名",
					Default: "小王",
					Verify:  "required",
					Desc:    "必填",
				},
				{
					Field:   "age",
					Title:   "年龄",
					Default: 18,
					Verify:  "required|positiveInt",
					Desc:    "必填，必须为正整数",
				},
				{
					Field:   "sex",
					Title:   "性别",
					Default: "男",
					Verify:  "required|in:男,女",
					Desc:    "必填，可选值：男/女",
				},
			}
			return
		}).
		Rows(func(i *builder.Import, rows []*yimport.Row) (err error) {
			for _, row := range rows {
				row.Success()
			}
			return
		})

	ctrl.RenderImport(ctx, importBuilder)
}
